package info.techgeek.labs.regex;

import info.techgeek.labs.String.StringSupplier;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
	
public class RegexPatternTest {
		
	public static void main(String args[]) throws IOException{
		

		List<String> list = new ArrayList<String>(); 
		RegexPatternTest patternTest = new RegexPatternTest();
		String params = null;
		
		System.out.println("Enter Sting");
//		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
//		String string = br.readLine();
		StringSupplier stringSupplier = new StringSupplier();
		String string  = stringSupplier.getString();
		System.out.println("String length "+string.length());
		
		long t = System.currentTimeMillis(); 
		String[] strAmb = string.split("&");
		for(int i=1 ;i<strAmb.length;i++){
//			System.out.println("Amber spit "+strAmb[i]);
			String[] strSpac = strAmb[i].split(" ");
//			System.out.println("Space spit "+strSpac[0]);
			String[] strSemi = strSpac[0].split(",");
//			System.out.println("Comma spit "+strSemi[0]);
			String[] strOr = strSemi[0].split("||");
//			System.out.println("Or spit "+strOr[0]);
			params = patternTest.getSuffix(strSemi[0]);
//			System.out.println("params "+params); 
			list.add(params);
			
		}
		System.out.println("--------------------------------------------------");
		for(String string2 : list){
//			System.out.println("String "+string2);
		}
		 System.out.println("Time Taken For Split Logic :" +( System.currentTimeMillis() -t));
	}
	
	private String getSuffix(String openString){
		openString = "&"+openString;
//	 	System.out.println("Begin getSuffix "+openString);
		String suffix = "";
//		List<String> list = new ArrayList<String>(); 
		boolean startAppend = false;
		for(int i = 0;i<openString.length();i++){
//			System.out.println("Inside For Loop ");
			char character =  openString.charAt(i);
//			System.out.println("Character "+character);
			if(startAppend){
//				System.out.println("Inside Start Append ");
				if(",".equals(String.valueOf(character)) || " ".equals(String.valueOf(character)) || "|".equals(String.valueOf(character))){
//					System.out.println("Inside If the Check of , Space");
//					List<IiParam> paramList = (ArrayList<IiParam>)navigationDao.getParamType(suffix);
//					System.out.println("suffix "+suffix);
//					list.add(suffix);
//					suffix = "";
					startAppend = false;
				}else{
					suffix += character;
//					System.out.println("Inside Else "+suffix);
				}
			}
			if("&".equals(String.valueOf(character))){
//				System.out.println("Inside & Check");
				startAppend = true;
			}
		}
		if(!suffix.equals("")){
//			list.add(suffix);
		}
//		System.out.println("End getSuffix "+suffix);
		return suffix;
 }
	
	
	
}
